package com.shengyin.ec.service.companyorder;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shengyin.ec.model.dao.companyorder.CompanyOrderDao;
import com.shengyin.ec.model.entity.CompanyOrder;
import com.shengyin.ec.service.order.OrderService;


@Service("companyOrderService")
public class CompanyOrderServiceImpl implements CompanyOrderService {

	@Autowired 
	CompanyOrderDao companyOrderDao;
	
	@Autowired
	OrderService orderService;
	
	public void createCompanyOrder(CompanyOrder companyOrder){
		
		companyOrderDao.save(companyOrder);
	}
	
	public List<CompanyOrder> getCompanyOrderList(){
		
		return companyOrderDao.getCompanyOrderList();
	}
	
	public List<CompanyOrder> getCompanyOrderList(int offset,int pageSize){
		
		return companyOrderDao.getCompanyOrderList(offset,pageSize);
	}
	
	public Long getTotal(){
		return companyOrderDao.getTotal();
	}
	
	public CompanyOrder getCompanyOrderById(String id){
		return companyOrderDao.getCompanyOrderById(id);
	}
	
	public void deleteSelectedOrders(String ids[]){
		if(ids!=null){
			Long[] idsl=new Long[ids.length];
			for(int i=0;i<ids.length;i++){
				if(ids[i]!=null||!ids[i].isEmpty()){
					idsl[i]=Long.valueOf(ids[i].trim());
				}
				
			}
			companyOrderDao.deleteSelectedOrders(idsl);
	}
}
	
	@Override
	public void removeOrderById(long id) {
		CompanyOrder companyOrder = companyOrderDao.get(id);
		orderService.deleteRelateOrder(companyOrder.getOrderId());
		companyOrderDao.deleteByKey(id);
	}
	
	public void updateComState(CompanyOrder companyOrder){
		companyOrderDao.updateComState(companyOrder);
	}

	/*public List<CompanyOrder> getCompanyOrderById(String orderId){
		
		return companyOrderDao.getCompanyOrderById(orderId);
	}
	
	public List<CompanyOrder> getCompanyOrderListById(String orderId,int offset,int pageSize){
		return companyOrderDao.getCompanyOrderListById(orderId,offset, pageSize);
	}
	
	public List<CompanyOrder> getCompanyOrderListByState(String orderState, int offset, int pageSize){
		return companyOrderDao.getCompanyOrderListByState(orderState,  offset, pageSize);
	}
	
	public List<CompanyOrder> getCompanyOrderByState(String orderState){
		return companyOrderDao.getCompanyOrderByState(orderState);
	}
	
	public List<CompanyOrder> getCompanyOrderListByBE(String beginTime,String endTime,int offset, int pageSize){
		return companyOrderDao.getCompanyOrderListByBE(beginTime,endTime,offset,  pageSize);
	}
	
	public List<CompanyOrder> getCompanyOrderByBE(String beginTime,String endTime){
		return companyOrderDao.getCompanyOrderByBE(beginTime, endTime);
	}
	
    public List<CompanyOrder> getCompanyOrderListByCompany(String company,int offset, int pageSize){
    	return companyOrderDao.getCompanyOrderListByCompany(company,offset,pageSize);
    }
	
	public List<CompanyOrder> getCompanyOrderByCompany(String company){
		return companyOrderDao.getCompanyOrderByCompany(company);
	}
	
    public List<CompanyOrder> getCompanyOrderListByComStat(String company,String orderState, int offset, int pageSize){
    	return companyOrderDao.getCompanyOrderListByComStat(company,orderState,offset,pageSize);
    }
	
	public List<CompanyOrder> getCompanyOrderByComStat(String company, String orderState){
		return companyOrderDao.getCompanyOrderByComStat(company,orderState);
	}
	
    public List<CompanyOrder> getCompanyOrderListByComBE(String company,String beginTime,String endTime, int offset, int pageSize){
    	return companyOrderDao.getCompanyOrderListByComBE(company,beginTime,endTime,offset,pageSize);
    }
	
	public List<CompanyOrder> getCompanyOrderByComBE(String company, String beginTime,String endTime){
		return companyOrderDao.getCompanyOrderByComBE(company,beginTime,endTime);
	}
	
    public List<CompanyOrder> getCompanyOrderListByComBEStat(String company,String beginTime,String endTime,String orderState, int offset, int pageSize){
	return companyOrderDao.getCompanyOrderListByComBEStat(company,beginTime,endTime,orderState,offset,pageSize);
    }
	
	public List<CompanyOrder> getCompanyOrderByComBEStat(String company,String beginTime,String endTime,String orderState){
		return companyOrderDao.getCompanyOrderByComBEStat(company,beginTime,endTime,orderState);
	}
	
	public List<CompanyOrder> getCompanyOrderListByBEStat(String beginTime,String endTime,String orderState, int offset, int pageSize){
		 return companyOrderDao.getCompanyOrderListByBEStat(beginTime,endTime,orderState,offset,pageSize);
	}
		
    public List<CompanyOrder> getCompanyOrderByBEStat(String beginTime,String endTime,String orderState){
			return companyOrderDao.getCompanyOrderByBEStat(beginTime,endTime,orderState);
    }*/
    
    
}
